﻿<?php
require_once('connections/mysqlDB.php');
//require("class.phpmailer.php"); 
require('smarty_connect.php');

$smarty = new smarty_connect;
$dbConn = new mysqli(HOST,USER,PWD,DB);
$dbConn->query("SET NAMES 'utf8'");

$email=$_POST['myemail']; 

$stmt1 = $dbConn->query("select pwd from registrant where email = \"$myemail\"");
$cnt = $stmt1->num_rows;

if ($cnt == 0 ) {
$smarty->assign('error','您的email 不存在系統，email does not exist.');
$smarty->display('error.tpl');
}

if ($cnt == 1) {

while ($row = $stmt1->fetch_assoc()) {
$pwd = $row["pwd"];
};

$to=$email;
$subject = "慕主特會 email密碼, FRCC Password Request";
$message = "
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
</head>
<body>
Here is the password: $pwd
</body>
</html>";

// Always set content-type when sending HTML email

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";// More headers
$headers .= 'From:FRCC Admin<support@frccinnerlife.org>' . "\r\n";
$headers .= "\r\n";

$mail = mail($to,$subject,$message,$headers);
  
if(!$mail) {   
    $smarty->assign('error','Mailer error:' . $mail->ErrorInfo);
  $smarty->display('error.tpl');
} else {   
   $smarty->assign('error','您的密碼將在兩小時內送出, Password will be sent within 2 hours');
  $smarty->display('error.tpl');
}  

$stmt1->close();
$dbConn->close();



}

?>